package dancrawler.client.gamecmd;

import dancrawler.common.Misc;
import dancrawler.client.Client;
import dancrawler.client.GameObject;
import dancrawler.proto.cmd.CmdHandler;
import dancrawler.server.netMsg;

/**
 *
 */
public class CmdNewObj extends CmdHandler{

    private Client client;
    public CmdNewObj(Client client)
    {
        this.client = client;
    }

    @Override
    public void handleCmd(netMsg msg) {
       int x = Misc.bytesToShort(msg.getArgs()[0]);
       int y = Misc.bytesToShort(msg.getArgs()[1]);
       int oid = Misc.bytesToShort(msg.getArgs()[3]);
       String type = new String(msg.getArgs()[2]);

       GameObject obj = new GameObject(type, x, y, true);
       client.getObjectRegister().registerGameObject(obj, oid);
       client.getWorld().addObj(obj, x, y);
    }

    @Override
    public int getNumArgs() {
        return 4;
    }

    @Override
    public int getId() {
        return 6;
    }

    @Override
    public int getArgSize(int n) {
        int[] argsize = {2, 2, -1, 2};
        if(n > getNumArgs()-1)
        {
            return 0;
        }
        return argsize[n];
    }

    @Override
    public CmdHandler getHandler() {
        return this;
    }

}
